<?php
class View
{
	protected $filename="";
	protected $data=array();
	
	function __construct($filename)
	{
		$this->filename = $filename;
	}
	
	function __set($name, $value)
	{
		$this->data[$name]=$value;
	}
	
	function __toString()
	{
		return $this->render();
	}
	
	function render()
	{
		//open a buffer
		ob_start();

		// Import the view variables to local namespace
		extract($this->data, EXTR_SKIP);
		
		include $this->filename;

		// Fetch the output and close the buffer
		return ob_get_clean();
	}
}
?>